<?php
/**
 * @var $this \yii\web\View
 * @var $model \app\modules\admin\models\AuthItem
 * @var $content \app\modules\admin\components\ItemController
 * Created by PhpStorm.
 * User: jiangjunxian
 * Date: 2016/12/13
 * Time: 16:48
 */
use app\assets\JUIAsset;
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Html;

$content = $this->context;

$rules = Yii::$app->authManager->getRules();
unset($rules[\app\modules\admin\components\RouteRule::RULE_NAME]);
$source = \yii\helpers\Json::htmlEncode(array_keys($rules));

$js = <<<JS
	$('#rule_name').autocomplete({
		source: $source
	});
JS;

JUIAsset::register($this);
$this->registerJs($js);
?>
<div class="col-sm-8 col-sm-offset-2">
	<div class="box box-primary">
		<?php $form = ActiveForm::begin(['id'=>'item-form']) ?>
		<div class="box-header">
			<h3 class="box-title"><?= $this->title ?></h3>
		</div>

		<div class="box-body">
			<div class="col-sm-6">
				<?= $form->field($model, 'name')->textInput(['maxLength'=>64]) ?>

				<?= $form->field($model, 'description')->textarea(['rows'=>4]) ?>
			</div>
			<div class="col-sm-6">
				<?= $form->field($model, 'ruleName')->textInput(['id'=>'rule_name']) ?>

				<?= $form->field($model, 'data')->textarea(['rows'=>6]) ?>
			</div>
		</div>
		<div class="box-footer">
			<?= Html::submitButton($model->isNewRecord ? '新建' : '更新', [
				'class' => 'pull-right btn ' . ($model->isNewRecord ? 'btn-success' : 'btn-primary')
			]); ?>
		</div>
		<?php ActiveForm::end() ?>
	</div>
</div>
